package com.ess.result;


import java.io.Serializable;


public class ResultResponse<T> implements Serializable {

    private static final long serialVersionUID = -4696898674758059398L;

    private int code;

    private String message;

    private T data;

    private boolean ok = true;

    public ResultResponse(int code, String message, T data) {
        this.code = code;
        this.ok = code == 200;
        this.message = message;
        this.data = data;
    }


    public ResultResponse(int code, T data) {
        this.code = code;
        this.ok = code == 200;
        this.data = data;
    }

    public ResultResponse(T data) {

        this.data = data;
    }

    public ResultResponse() {

    }

    public static ResultResponse success(Object data) {
        ResultResponse<Object> result = new ResultResponse<Object>();
        result.setCode(ResultCode.SYSTEM_SUCCESS_CODE.getCode());
        result.setData(data);
        return result;
    }

    public static ResultResponse success(Object data, String message) {

        ResultResponse<Object> result = new ResultResponse<Object>();
        result.setCode(ResultCode.SYSTEM_SUCCESS_CODE.getCode());
        result.setMessage(message);
        result.setData(data);
        return result;
    }

    public static ResultResponse error(ResultCode code) {

        ResultResponse<Object> result = new ResultResponse<Object>();
        result.setCode(code.getCode());
        result.setMessage(code.getDesc());
        return result;
    }

    public static ResultResponse error(ResultCode code, String message) {

        ResultResponse<Object> result = new ResultResponse<Object>();
        result.setCode(code.getCode());
        result.setMessage(message);
        return result;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
        this.ok = code == 200;
    }

    public boolean getOk() {
        return ok;
    }

    public void setOk(boolean ok) {
        this.ok = ok;
    }

    public String getMessage() {
        return message;
    }

    public ResultResponse setMessage(String message) {
        this.message = message;
        return this;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }


}
